package com.moqianfan.mcuassistant.fragment.tools;

import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.GridView;

import com.moqianfan.mcuassistant.R;
import com.moqianfan.mcuassistant.activity.BlueToothActivity;
import com.moqianfan.mcuassistant.activity.BpsCalculActivity;
import com.moqianfan.mcuassistant.activity.CalaulatorActivity;
import com.moqianfan.mcuassistant.activity.LedCodeActivity;
import com.moqianfan.mcuassistant.activity.OrderActivity;
import com.moqianfan.mcuassistant.activity.PCBTransActivity;
import com.moqianfan.mcuassistant.activity.TimeActivity;
import com.moqianfan.mcuassistant.activity.WebInfoActivity;
import com.moqianfan.mcuassistant.adapter.CommDataAdapter;
import com.moqianfan.mcuassistant.bean.GridBean;
import com.moqianfan.mcuassistant.fragment.BaseFragment;

import java.util.ArrayList;

import butterknife.BindView;

/**
 * Created by Administrator on 2016/11/5.
 * 工具页面
 */

public class ToolsFragment extends BaseFragment implements AdapterView.OnItemClickListener {
    @BindView(R.id.grid_tools)
    GridView mGridView;

    @Override
    public View findViews(LayoutInflater inflater, ViewGroup container) {
        return inflater.inflate(R.layout.fragment_tools, container, false);
    }

    public void initViews() {
        ArrayList<GridBean> gridBeen = new ArrayList<>();
        gridBeen.add(new GridBean(R.drawable.tools_led, "数码管段码"));
        gridBeen.add(new GridBean(R.drawable.tools_time, "定时计数器"));
        gridBeen.add(new GridBean(R.drawable.tools_hex, "进制计算器"));
        gridBeen.add(new GridBean(R.drawable.tools_order, "汇编指令码"));
        gridBeen.add(new GridBean(R.drawable.tools_bps, "波特率计算"));
        gridBeen.add(new GridBean(R.drawable.tools_pcb, "PCB单位换算"));
        gridBeen.add(new GridBean(R.drawable.tools_blue, "蓝牙助手"));
        gridBeen.add(new GridBean(R.drawable.tools_555, "555计算器"));
        gridBeen.add(new GridBean(R.drawable.tools_cha, "差动放大器"));

        BaseAdapter adapter = new CommDataAdapter<GridBean>(gridBeen, R.layout.view_item_gridview) {
            @Override
            public void bindView(ViewHolder holder, GridBean obj) {
                holder.setImageResource(R.id.image_icon, obj.getResId());
                holder.setText(R.id.txt_icon, obj.getiName());
            }
        };
        mGridView.setAdapter(adapter);
        mGridView.setOnItemClickListener(this);
    }

    @Override
    public void loadData() {

    }

    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
        switch (i) {
            case 0:
                Intent intent0 = new Intent();
                intent0.setClass(getActivity(), LedCodeActivity.class);
                getActivity().startActivity(intent0);
                break;
            case 1:
                Intent intent1 = new Intent();
                intent1.setClass(getActivity(), TimeActivity.class);
                getActivity().startActivity(intent1);
                break;
            case 2:
                Intent intent2 = new Intent();
                intent2.setClass(getActivity(), CalaulatorActivity.class);
                getActivity().startActivity(intent2);
                break;
            case 3:
                Intent intent = new Intent();
                intent.setClass(getActivity(), OrderActivity.class);
                getActivity().startActivity(intent);
                break;
            case 4:
                Intent intent4 = new Intent();
                intent4.setClass(getActivity(), BpsCalculActivity.class);
                getActivity().startActivity(intent4);
                break;
            case 5:
                Intent intent6 = new Intent();
                intent6.setClass(getActivity(), PCBTransActivity.class);
                getActivity().startActivity(intent6);
                break;
            case 6:
                Intent intent7 = new Intent();
                intent7.setClass(getActivity(), BlueToothActivity.class);
                getActivity().startActivity(intent7);
                break;
            case 7:
                Intent intent8 = new Intent();
                intent8.putExtra("title", "555计算器");
                intent8.putExtra("url", "file:///android_asset/555.html");
                intent8.putExtra("flag", 0);
                intent8.setClass(getActivity(), WebInfoActivity.class);
                getActivity().startActivity(intent8);
                break;
            case 8:
                Intent intent9 = new Intent();
                intent9.putExtra("title", "差动放大器");
                intent9.putExtra("url", "file:///android_asset/chadong.html");
                intent9.putExtra("flag", 0);
                intent9.setClass(getActivity(), WebInfoActivity.class);
                getActivity().startActivity(intent9);
                break;

        }
        getActivity().overridePendingTransition(R.anim.push_left_in,
                R.anim.push_left_out);
    }
}
